package com.rimi.controller;

import com.rimi.bean.User;
import com.rimi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
public class LoginController {

    @Autowired
    private UserService userService;

    @RequestMapping("/login1")
    public String login(HttpServletRequest req, HttpServletResponse resp){
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String email = req.getParameter("email");
        String phone = req.getParameter("phone");
        User user = new User();
        user.setEmail(email);
        user.setPassword(password);
        user = userService.loginByEmail(user);
        if (user != null){
            req.setAttribute("user",user);
            return "index";
        }
        return "login";
    }

    @RequestMapping("/login")
    public String to(){
        return "login";
    }

}
